<?php
    use User\Model\QuestionnaireModel;
?>
<style>
    .table>thead>tr>th{text-align: center}
    .table>tbody>tr>td{vertical-align: middle; text-align: center}
    .table>tbody>tr>td>a{margin-top:5px}
</style>
<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">
                <span>问卷测试</span>
            </h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a style="margin-left:7px" href="{:U('User/Questionnaire/edit')}" class="btn btn-success">新建</a>
                    <form class="input-group" action="/User/Questionnaire/index" style="width: 300px;float:right">
                        <input type="text" class="form-control" name="title" placeholder="输入标题搜索" value="{$title}">
                        <span class="input-group-btn">
							<button class="btn btn-default" type="submit">
								<i class="fa fa-search"></i>
							</button>
						</span>
                    </form>

                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th width="5%">编号</th>
                                <th width="20%">名称</th>
                                <th width="30%">链接首页地址</th>
                                <th width="10%">状态</th>
                                <th width="10%">创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="list" id="item">
                                <tr>
                                    <td>{$item.id}</td>
                                    <td>{$item.title}</td>
                                    <td>{$item.link}</td>
                                    <td>
                                        <if condition="$item.status eq QuestionnaireModel::QUESTIONNAIRE_ACTIVE">
                                            <span class="label label-success">已发布</span>
                                        <else/>
                                            <span class="label label-warning">已停用</span>
                                        </if>
                                    </td>
                                    <td>{$item.createdate}</td>
                                    <td style="text-align: left">
                                        <a type="button" href="{:U('User/Questionnaire/edit', array('id' => $item['id']))}" class="btn btn-info">编辑</a>
                                        <a type="button" href="{:U('User/Questionnaire/question', array('id' => $item['id']))}" class="btn btn-primary">题目</a>
                                        <a type="button" href="javascript:;" onclick="return statusQuestionnaire({$item['id']}, 'active');" class="btn btn-success">发布</a>
                                        <a type="button" href="javascript:;" onclick="return statusQuestionnaire({$item['id']}, 'pending');" class="btn btn-warning">停用</a>
                                        <a type="button" href="javascript:;" onclick="return statusQuestionnaire({$item['id']}, 'delete');" class="btn btn-danger">删除</a>
                                        <a type="button" href="{:U('User/Questionnaire/statistics', array('id' => $item['id']))}" class="btn btn-default">数据统计</a>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                    <div class="pages">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function statusQuestionnaire(id, status){
        if(status == "active"){
            if(!confirm('确认发布吗？')) return false;
        }else if(status == "pending"){
            if(!confirm('确认停用吗？')) return false;
        }else{
            if(!confirm('确认删除吗？')) return false;
        }
        $.ajax({
            data: {id: id, status: status},
            dataType: 'json',
            url: '/User/Questionnaire/statusQuestionnaire',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }
</script>